package cn.xn.hrms.api.controller;

import cn.xn.hrms.api.dto.res.PersonalRewardDTO;
import cn.xn.hrms.domain.service.PersonalRewardService;
import cn.xn.hrms.domain.utils.ResultVo;
import cn.xn.hrms.api.dto.req.PersonalRewardReqDTO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Set;

/**
 * @author ysz
 */
@RestController
public class PersonalRewardController {

    @Resource
    PersonalRewardService personalRewardService;

    /**
     * 分页查询奖惩列表
     *
     * @param page
     * @param size
     * @param departmentId
     * @param personalId
     * @param year
     * @param month
     * @return
     */
    @GetMapping("/reward/list")
    @ApiOperation("分页查询奖惩列表")
    public PageInfo<PersonalRewardDTO> list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                            @RequestParam(value = "size", defaultValue = "10") Integer size,
                                            @RequestParam(value = "departmentId", required = false) Integer departmentId,
                                            @RequestParam(value = "personalId", defaultValue = "0") Integer personalId,
                                            @RequestParam(value = "year", defaultValue = "0") Integer year,
                                            @RequestParam(value = "month", defaultValue = "0") Integer month) {
        return personalRewardService.findAll(year, month, departmentId, personalId, page, size);
    }

    /**
     * 奖惩列表
     *
     * @return
     */
    @GetMapping("/reward/all")
    @ApiOperation("奖惩列表")
    public List<PersonalRewardDTO> all() {
        return personalRewardService.all();
    }

    /**
     * 新增奖惩
     *
     * @param personalRewardReqDTO
     * @return
     */
    @PostMapping("/reward")
    @ApiOperation("新增奖惩")
    public ResultVo insert(@RequestBody @Valid PersonalRewardReqDTO personalRewardReqDTO) {
        personalRewardService.insert(personalRewardReqDTO);
        return ResultVo.success();
    }

    /**
     * 修改奖惩
     *
     * @param personalRewardReqDTO
     * @param id
     * @return
     */
    @PutMapping("/reward/{id}")
    @ApiOperation("修改奖惩")
    public ResultVo update(@RequestBody @Valid PersonalRewardReqDTO personalRewardReqDTO, @PathVariable Integer id) {
        personalRewardService.updateById(id, personalRewardReqDTO);
        return ResultVo.success();
    }

    /**
     * 删除奖惩(支持批量）
     *
     * @param id
     * @return
     */
    @DeleteMapping("/reward/delete")
    @ApiOperation("删除奖惩(支持批量）")
    public ResultVo deleteIdIn(@RequestBody Set<Integer> id) {
        personalRewardService.deleteByIdIn(id);
        return ResultVo.success();
    }
}
